home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / GDIMETA.PAK / INIT.C < prev    next >
C/C++ Source or Header  |  1997-05-06  |  6KB  |  148 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993-1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE:   init.c
  9. //
  10. //  PURPOSE:   Performs application and instance specific initialization.
  11. //
  12. //  FUNCTIONS:
  13. //    InitApplication() - Initializes window data and registers window.
  14. //
  15. //  COMMENTS:
  16. //
  17.  
  18. #include <windows.h>            // required for all Windows applications
  19. #include <windowsx.h>
  20. #include <commctrl.h>
  21. #include "globals.h"            // prototypes specific to this application
  22. #include "resource.h"
  23. #include "palctrl.h"            // prototype for RegisterPalCtrlClass
  24.  
  25. HINSTANCE hInst;                // current instance
  26. HCURSOR   hcursHourGlass;       // IDC_WAIT cursor
  27.  
  28. char szAppName[9];              // The name of this application
  29. char szTitle[40];               // The title bar text
  30.  
  31.  
  32. //
  33. //  FUNCTION: InitApplication(HINSTANCE, int)
  34. //
  35. //  PURPOSE: Initializes window data and registers window class.
  36. //
  37. //  PARAMETERS:
  38. //    hInstance - The handle to the instance of this application that
  39. //                is currently being executed.
  40. //    nCmdShow  - Specifies how the main window is to be displayed.
  41. //
  42. //  RETURN VALUE:
  43. //    TRUE  - Success
  44. //    FALSE - Initialization failed
  45. //
  46. //  COMMENTS:
  47. //
  48. //    This function is called at application initialization time.  It
  49. //    performs initialization tasks for the current application instance.
  50. //    Unlike Win16, in Win32, each instance of an application must register
  51. //    window classes.
  52. //
  53. //    In this function, we initialize a window class by filling out a data
  54. //    structure of type WNDCLASS and calling the Windows RegisterClass()
  55. //    function.  Then we create the main window and show it.
  56. //
  57. //
  58.  
  59. BOOL InitApplication(HINSTANCE hInstance, int nCmdShow)
  60. {
  61.     WNDCLASSEX wc;
  62.     HWND       hwnd; // Main window handle.
  63.  
  64.     // Load the application name and description strings.
  65.  
  66.     LoadString(hInstance, IDS_APPNAME, szAppName, sizeof(szAppName));
  67.     LoadString(hInstance, IDS_DESCRIPTION, szTitle, sizeof(szTitle));
  68.  
  69.     // Save the instance handle in static variable, which will be used in
  70.     // many subsequence calls from this application to Windows.
  71.  
  72.     hInst = hInstance; // Store instance handle in our global variable
  73.  
  74.     // Get handle to hourglass cursor for lengthy operations
  75.  
  76.     hcursHourGlass = LoadCursor(NULL, IDC_WAIT);
  77.  
  78.     // Fill in window class structure with parameters that describe the
  79.     // main window.
  80.  
  81.     wc.cbSize        = sizeof(WNDCLASSEX);
  82.     wc.style         = CS_HREDRAW | CS_VREDRAW; // Class style(s).
  83.     wc.lpfnWndProc   = (WNDPROC)WndProc;        // Window Procedure
  84.     wc.cbClsExtra    = 0;                       // No per-class extra data.
  85.     wc.cbWndExtra    = 0;                       // No per-window extra data.
  86.     wc.hInstance     = hInstance;               // Owner of this class
  87.     wc.hIcon         = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPICON)); // Icon name from .RC
  88.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW); // Cursor
  89.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); // Default color
  90.     wc.lpszMenuName  = szAppName;               // Menu name from .RC
  91.     wc.lpszClassName = szAppName;               // Name to register as
  92.     wc.hIconSm       = LoadImage(hInstance,        // Load small icon image
  93.                                  MAKEINTRESOURCE(IDI_APPICON),
  94.                                  IMAGE_ICON,
  95.                                  16, 16,
  96.                                  0);
  97.  
  98.     // Register the window class and return FALSE if unsuccesful.
  99.  
  100.     if (!RegisterClassEx(&wc))
  101.     {
  102.         //Assume we are running on NT where RegisterClassEx() is
  103.         //not implemented, so let's try calling RegisterClass().
  104.  
  105.         if (!RegisterClass((LPWNDCLASS)&wc.style))
  106.             return FALSE;
  107.     }
  108.  
  109.     // Register window class for the client window.
  110.  
  111.     wc.lpfnWndProc   = ClientWndProc;
  112.     wc.hIcon         = NULL;
  113.     wc.lpszMenuName  = NULL;
  114.     wc.lpszClassName = "ClientWndClass";
  115.  
  116.     if (!RegisterClass((LPWNDCLASS)&wc.style))
  117.            return FALSE;
  118.     
  119.     // Register palette control class
  120.  
  121.     if (!RegisterPalCtrlClass(hInstance))
  122.     {
  123.         return FALSE;
  124.     }
  125.  
  126.     // Create a main window for this application instance.
  127.     hwnd = CreateWindow(szAppName,           // See RegisterClass() call
  128.                         szTitle,             // Text for window title bar
  129.                         WS_OVERLAPPEDWINDOW, // Window style
  130.                         CW_USEDEFAULT, 0,    // Use default positioning
  131.                         CW_USEDEFAULT, 0,    // Use default size
  132.                         NULL,                // Overlapped has no parent
  133.                         NULL,                // Use the window class menu
  134.                         hInstance,           // This instance owns this window
  135.                         NULL                 // Don't need data in WM_CREATE
  136.     );
  137.  
  138.     // If window could not be created, return "failure"
  139.     if (!hwnd)
  140.         return FALSE;
  141.  
  142.     // Make the window visible; update its client area; and return "success"
  143.     ShowWindow(hwnd, nCmdShow);  // Show the window
  144.     UpdateWindow(hwnd);          // Sends WM_PAINT message
  145.  
  146.     return TRUE;                 // We succeeded...
  147. }
  148.